/*
 *
A(void)
A(void)
A(void)
failed

 */

#include <iostream>
#include <cstdio>
#include <csetjmp>
using namespace std;
jmp_buf env;
class A{
	public:
		A(void){
			cout << "A(void)" << endl;
		}
		~A(){
			cout << "~A()" << endl;
		}
};
int func3(){
	A c;
	FILE *fp = fopen("./a.txt", "r");
	if(fp  == NULL){
		longjmp(env, -1); //跳转到setjmp位置执行
	}
	cout << "open a.txt successed" << endl;
	fclose(fp);
	return 0;
}
int func2(){
	A b;
	func3();
	return 0;
}
int func1(void){
	A a;
	func2();
	return 0;
}
int main(void){
	if(setjmp(env) == 0){ //保存当前栈的快照
		func1();
	}
	else{
		cout << "failed" << endl;
		return -1;
	}
	return 0;
}
